interface INameInfo {
  firstName: string
  lastName: string
}

const getFullName = ({ firstName, lastName }: INameInfo): string => {
  return `${firstName} ${lastName}`
}

getFullName({ firstName: '刘', lastName: '柏麟' })

interface IVegetables {
  color?: string
  readonly type: string
  // [propName: string]: any // 索引签名
}

const getVegetables = ({ color, type }: IVegetables) => {
  return `A ${color ? color + '' : ''} ${type}`
}

// 对象兼容性
const vegetables = { type: 'tomato', size: 3 }

console.log(getVegetables(vegetables))

const myObj: IVegetables = {
  type: '嘿嘿',
}

console.log(myObj)
// myObj.type = '' // 报错，因为是只读属性

interface IArrinter {
  0: number
  readonly 1: string
}

const arr: IArrinter = [0, '2']

// arr[1] ='' 报错，只读属性

// 函数接口
interface IAddFunc {
  (num1: number, num2: number): number
}

const addFunc: IAddFunc = (num1: number, num2: number): number => {
  return num1 + num2
}

interface RoleDic {
  [id: number]: string
}

// const role1: RoleDic = {
//   0: 'super_admin',
//   1: 'super_man',
// }

interface RoleDic {
  [id: string]: string
}

const role2: RoleDic = {
  a: 'super_admin',
  1: 'admin',
}

interface IVagetables {
  color: string
}

interface ITomato extends IVagetables {
  radius: number
}

interface Carrot extends IVagetables {
  length: number
}

const carrot: Carrot = {
  color: 'red',
  length: 1111,
}

interface ICount {
  (): void
  count: number
}

const add: ICount = () => {
  add.count++
}
add.count = 0
add()
console.log(add.count)
